package com.xh3140.xwidget.dialog.view;

import android.content.Context;
import android.text.method.ScrollingMovementMethod;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.LinearLayoutCompat;

import com.xh3140.xwidget.dialog.params.ContentParams;

/**
 * 对话框内容主体视图
 */
public class ContentView extends AppCompatTextView {

  public ContentView(@NonNull Context context) {
    super(context);
    setLayoutParams(new LinearLayoutCompat.LayoutParams(
            LinearLayoutCompat.LayoutParams.MATCH_PARENT,
            LinearLayoutCompat.LayoutParams.WRAP_CONTENT, 1f));
  }

  /**
   * 配置视图
   *
   * @param params 内容主体视图配置属性
   */
  public ContentView configView(@NonNull ContentParams params) {
    setText(params.text);
    setTextSize(params.textSize);
    setTextColor(params.textColor);
    setTypeface(getTypeface(), params.typeface);
    setGravity(params.gravity);
    setBackgroundColor(params.backgroundColor);
    setMovementMethod(ScrollingMovementMethod.getInstance());
    if (params.padding != null) {
      setPaddingRelative(params.padding[0], params.padding[1], params.padding[2], params.padding[3]);
    }
    setVisibility(params.text == null ? GONE : VISIBLE);
    if (params.callback != null) {
      params.callback.callback(this);
    }
    return this;
  }
}
